﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LGCourt.Logic.BLL;
using KMFrame.Permission.Util;

namespace lgweb.user
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            int usertype = this.rdocredentials1.Checked ?0 : this.rdocredentials2.Checked ? 0 : this.rdocredentials3.Checked ? 1 : 0;

            string sUserName = this.txtLoginCard.Value;
            string sPwd = this.txtLoginPwd.Value;

            UserInfo bll = new UserInfo();

            PUserInfo result = (PUserInfo)bll.Login(sUserName, sPwd,usertype);

            if (result != null)
            {
                UserSession user = new UserSession(result.UserID, result.UserName, result.UserGUID);
                SessionBox.CreateUserSession(user);

                if (usertype==0)
                {
                    Response.Redirect("/user/index.aspx");
                }
                else
                {
                    Response.Redirect("/lawyer/index.aspx");
                }
            }
            else
            {
                this.spMessage.InnerHtml = "登录失败，请检查用户和密码是否正确，并重新登录！";
            }

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            UserInfo bll = new UserInfo();
            int identityType = this.rdoactivation1.Checked?0:1;

            int result = (int)bll.CheckActive(identityType, this.txtActiveCard.Value);

            if (result == -1)
            {
                this.tdMessages.InnerHtml = "该证件号码不存在！您可以先去注册！";
            }
            else if (result == 1)
            {
                this.tdMessages.InnerHtml = "该证件号码已经激活过了，您直接登录即可！";
            }
            else
            {
                Response.Redirect("/user/AccountActivation.aspx?type="+identityType.ToString()+"&card="+this.txtActiveCard.Value);
            }
        }
    }
}